package org.geektimes.serialize.impl;

import org.geektimes.serialize.Serializer;

public abstract class AbstractSerializer<T> implements Serializer<T> {
    /**
     * 序列化对象。将给定的对象序列化成字节数组
     *
     * @param o 待序列化的对象
     */
    @Override
    public byte[] serialize(T t) {
        return doSerialize(t);
    }

    /**
     * 反序列化对象
     *
     * @param bytes 存放序列化数据的字节数组
     * @return 反序列化之后生成的对象
     */
    @Override
    public T deserialize(byte[] bytes, Class<T> typeClass) {
        return doDescrialize(bytes, typeClass);
    }

    public abstract byte[] doSerialize(T t);
    public abstract T doDescrialize(byte[] bytes, Class<T> typeClass);
}
